package com.atguigu.spzx.manager.controller;


import com.atguigu.spzx.manager.service.impl.SysMenuServiceImpl;
import com.atguigu.spzx.common.result.Result;
import com.atguigu.spzx.manager.vo.sysMenu.SysMenuQueryRespVo;
import com.atguigu.spzx.manager.vo.sysMenu.SysMenuQueryTreeVo;
import com.atguigu.spzx.manager.vo.sysMenu.SysMenuSaveReqVo;
import com.atguigu.spzx.manager.vo.sysMenu.SysMenuUpdateReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author flyduck
 * @since 2023-10-25
 */
@Api(tags = "菜单管理接口")
@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuServiceImpl sysMenuServiceImpl;

    @ApiOperation("菜单列表")
    @GetMapping("/getMenuTree")
    public Result<List<SysMenuQueryTreeVo>> getMenuTree(){
        List<SysMenuQueryTreeVo> list = sysMenuServiceImpl.getMenuTree();
        return Result.ok(list);
    }

    @ApiOperation("添加菜单")
    @PostMapping("/saveMenu")
    public Result<Void> saveMenu(@RequestBody SysMenuSaveReqVo reqVo){
        sysMenuServiceImpl.saveMenu(reqVo);
        return Result.ok();
    }

    @ApiOperation("根据id查询菜单")
    @GetMapping("/getMenuById/{id}")
    public Result<SysMenuQueryRespVo> getMenuById(@PathVariable("id")Long id){
        SysMenuQueryRespVo respVo = sysMenuServiceImpl.getMenuById(id);
        return Result.ok(respVo);
    }

    @ApiOperation("修改菜单")
    @PostMapping("/updateMenuById")
    public Result<Void> updateMenuById(@RequestBody SysMenuUpdateReqVo reqVo){
        sysMenuServiceImpl.updateMenuById(reqVo);
        return Result.ok();
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("/deleteMenuById/{id}")
    public Result deleteMenuById(@PathVariable("id")Long id){
        sysMenuServiceImpl.deleteMenuById(id);
        return Result.ok();
    }
}

